<template>
	<view class="goods-detail">
		<view class="head-wrapper" :style="'top:' + statusBarHeight">
			<view class="head-menu">
				<view class="iconfont iconxianxingxiangzuo" @click="returns"></view>
				<view class="iconfont iconzhuye" @click="goHome"></view>
			</view>
		</view>
		<scroll-view scroll-y="true" scroll-with-animation="true" :style="'height:' + height + 'px;'">
			<view id="past0">
				<productConSwiper :imgUrls="goodsitem.slider_image" :videoline="goodsitem.video_link"></productConSwiper>
				<view class="head-box">
					<view class=".head-qian">
						<view class="money">
							￥
							<span>{{ goodsitem.price}}</span>
						</view>
						<view class=""><u-icon style="margin-top: 15rpx;" name="zhuanfa" size="40rpx" @click="share"></u-icon></view>
					</view>
					<view class="head-title">{{ goodsitem.store_name }}</view>
					<view class="head-subtitle">
						<span>{{i18n.Original}} :￥{{ goodsitem.ot_price || ''}}</span>
						<span>{{i18n.Inventory}} : {{ goodsitem.stock || ''}}</span>
						<span>{{i18n.Sales}} : {{ goodsitem.sales||'0'}}</span>
					</view>
					<view class="head-bottom" @click="couponTap" style="margin-top: 20rpx;" v-if="coupon.list.length">
						<view class="acea-row">
							{{i18n.Discounts}} :
							<view class="activity" v-for="(item, index) in coupon.list" :key="index">{{i18n.Full}} {{ item.use_min_price }}{{i18n.Subtract}}{{ item.coupon_price }}</view>
						</view>
						<view class="iconfont iconxianxingxiangyou"></view>
					</view>
				</view>
				<view class="body-box">
					<view class="body-box-list">
						<view class="body-box-list-title">{{i18n.Fuwu}} :</view>
						<view class="body-box-list-text"><text>{{i18n.Serviceitem}}</text></view>
					</view>
					<view class="body-box-list">
						<view class="body-box-list-title">{{i18n.Sendout}} :</view>
						<!-- <view class="body-box-list-text"><text>{{i18n.Estimate}}</text></view> -->
						<view class="img">
							<view class="xian"></view>
							<view class="xian1"></view>
							<view class="">
								<image src="@/static/images/detail_import.png" mode=""></image>
								<view class="" style="color: #FD342A; z-index: 5;">{{ goodsitem.country }}</view>
							</view>
							<view>
								<image src="@/static/images/detail_warehouse.png" mode=""></image>
								<view class="" style="color: #FD342A;">{{ goodsitem.warehouse }}</view>
							</view>
							<view class="">
								<image src="@/static/images/detail_adress.png" mode=""></image>
								<view class="">当前所在地</view>
							</view>
						</view>
					</view>
					<view class="body-box-list" style="display: flex; " @click="joinCart">
						<view class="body-box-list-title">{{i18n.Selected}} :</view>
						<view style="flex: 1;"></view>
						<view class="iconfont iconxianxingxiangyou"></view>
					</view>
				</view>
				<!-- 商铺信息 -->
				<view class="store-wrapper" v-if="goodsitem.merchant && hide_mer_status != 1">
					<view class="store-hd">
						<view class="store-info">
							<view class="logo"><image :src="goodsitem.merchant.mer_avatar" mode=""></image></view>
							<view class="info">
								<view class="name">
									{{ goodsitem.merchant.mer_name || ''}}
									<text v-if="goodsitem.merchant.is_trader" class="font-bg-red ml8">{{i18n.Alreadyfollowed}}</text>
								</view>
								<!-- <view class="txt">{{ goodsitem.merchant.care_count || ''}}{{i18n.Attention}}</view> -->
							</view>
							<button @click="gostore" class="link" type="default">{{i18n.Shop}}</button>
						</view>
						<view class="score-wrapper">
							<view class="item">
								{{i18n.Serve}}
								<text>{{goodsitem.merchant.product_score || ''}}</text>
							</view>
							<view class="item">
								{{i18n.Describe}}
								<text>{{ goodsitem.merchant.service_score || ''}}</text>
							</view>
							<view class="item">
								{{i18n.Logistics}}
								<text>{{ goodsitem.merchant.postage_score || ''}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="title">{{i18n.Introduce}}</view>
				<jyf-parser :html="content.replace(/<br\/>/gi, '')" ref="article" :tag-style="tagStyle"></jyf-parser>
			</view>
			<view style="height: 60px;"></view>
		</scroll-view>
		<view class="footer acea-row row-between-wrapper">
			<view class="item" @click="couponTap2">
				<image class="iconfont" src="../../static/images/details_tabbar_service.png" mode=""></image>
				<view>{{i18n.Service}}</view>
			</view>

			<view @click="setCollect" class="item">
				<image class="iconfont" src="../../static/images/details_tabbar_collect_selected.png" v-if="goodsitem.isRelation" mode=""></image>
				<image class="iconfont" src="../../static/images/details_tabbar_collect_default.png" v-else mode=""></image>
				<view>{{i18n.Collecting}}</view>
			</view>
			<view class="animated item" :class="animated == true ? 'bounceIn' : ''" @click="goCart">
				<view class="iconfont">
					<image class="iconfont" src="/static/images/details_tabbar_shoppingcart.png" >
						<text class="num bg-color">{{ CartCount || 0 }}</text>
					</image>
				</view>
				<!-- <view class="iconfont icongouwuche">
					<text class="num bg-color">{{ CartCount || 0 }}</text>
				</view> -->
				<view>{{i18n.Cart}}</view>
			</view>
			<view class="bnt acea-row">
				<form @submit="joinCart" report-submit="true"><button class="joinCart bnts" form-type="submit">{{i18n.AddCart}}</button></form>
				<form @submit="goBuy" report-submit="true" v-if="attr.productSelect">
					<button class="buy bnts" form-type="submit" :disabled="attr.productSelect.stock == 0">{{i18n.Purchase}}</button>
				</form>
			</view>
		</view>
		<u-popup v-model="isopen" mode="bottom" height="200rpx">
			<view class="content">
				<button open-type="share" class="weix">
					<view class=""><u-icon name="weixin-circle-fill" color="#5eae72" size="80"></u-icon></view>
					<text style="font-size: 28rpx;">{{i18n.Friend}}</text>
				</button>
				<view class="haib" @click="goPoster">
					<view class=""><u-icon name="photo" color="#5391f1" size="80"></u-icon></view>

					<text style="font-size: 28rpx;">{{i18n.Poster}}</text>
				</view>
			</view>
		</u-popup>
		<productWindow
			:attr="attr"
			:isShow="1"
			:iSplus="1"
			@myevent="onMyEvent"
			@ChangeAttr="ChangeAttr"
			@ChangeCartNum="ChangeCartNum"
			@attrVal="attrVal"
			@iptCartNum="iptCartNum"
			id="product-window"
		></productWindow>
		<block v-if="coupon.coupon">
			<couponListWindow :coupon="coupon" @ChangCouponsClone="ChangCouponsClone" @ChangCoupons="ChangCoupons" @ChangCouponsUseState="ChangCouponsUseState"></couponListWindow>
		</block>
		<!-- 海报展示 -->
		<view class="mask" v-if="canvasStatus"></view>
		<canvas class="canvas" @longtap="Saveposters" canvas-id="myCanvas" v-if="canvasStatus">
			<image src="/static/images/poster-close.png" class="close" @click="posterImageClose" v-if="canvasStatus"></image>
			<view class="keep" v-if="canvasStatus">长按保存图片</view>
		</canvas>
	</view>
</template>

<script>
const globalData = getApp().globalData;
import { getCartCounts } from '@/api/order.js';
import { Context } from '@/utils/context.js';
import { getProductDetail, productadd, postCartAdd, getStoreDetail, collectAdd, collectDel } from '@/api/store.js';
import { getCoupons, getShopCoupons, goodsQrcode } from '@/api/api.js';
import { getappid } from '@/api/public.js';
import productConSwiper from '@/components/productConSwiper/index.vue';
import productWindow from '@/components/productWindow/index.vue';
import couponListWindow from '@/components/couponListWindow';
import { mapGetters } from 'vuex';
import parser from '@/components/jyf-parser/jyf-parser';
import Routine from '@/libs/routine';
import { APPID } from '@/config/app';
export default {
	components: { couponListWindow, productConSwiper, productWindow, 'jyf-parser': parser },
	data() {
		return {
			posters: false,
			storeImage: '', //海报产品图
			QRcodeImage: '', //二维码图
			posterbackgd: '/static/images/posterbackgd.png',
			canvasStatus: false, //海报绘图标签
			//属性是否打开
			coupon: {
				coupon: false,
				list: []
			},
			couponList: [], //优惠券
			tagStyle: {
				img: 'width:100%;'
			},
			content: '',
			background: {
				backgroundColor: '#ffffff'
			},
			statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
			height: 0,
			option: 0,
			sum: 1,
			CartCount: 0,
			mer_id: '',
			storeinfo: [],
			goodsid: '', //商品id
			goodsitem: { merchant: {} }, //商品列表
			cart_num: 1, //购买数量
			isOpen: false, //是否打开属性组件
			productValue: [], //系统属性
			attrValue: '', //已选属性
			attrTxt: globalData.$t('goods_details').Pleaseselect, //属性页面提示attrTxt
			attr: {
				cartAttr: false,
				productAttr: [],
				productSelect: {}
			},
			city: globalData.city,
			isopen: false, //是否打开分享组件
			create: false
		};
	},
	//用户点击右上角分享
	// #ifdef MP
	onShareAppMessage: function() {
		let that = this;
		return {
			title: that.goodsitem.store_name || '',
			imageUrl: that.goodsitem.image || '',
			path: '/pages/goods_details/index?id=' + that.goodsid
		};
	},
	//分享朋友圈
	onShareTimeline: function() {
		let that = this;
		return {
			title: that.goodsitem.store_name || '',
			imageUrl: that.goodsitem.image || '',
			path: '/pages/goods_details/index?id=' + that.goodsid
		};
	},
	// #endif
	computed: {
		i18n() {
			return globalData.$t('goods_details');
		},
		...mapGetters(['isLogin'])
	},
	methods: {
		// 关闭优惠券插件
		ChangCouponsClone: function() {
			this.$set(this.coupon, 'coupon', false);
		},
		// 打开优惠券插件
		couponTap: function() {
			let that = this;
			that.$set(that.coupon, 'coupon', true);
		},
		// 领取完毕移除当前页面领取过的优惠券展示
		ChangCoupons: function(e) {
			let coupon = e;
			let couponList = this.$util.ArrayRemove(this.couponList, 'goodsid', coupon.id);
			this.$set(this, 'couponList', couponList);
			this.getCouponList();
		},
		// 获取优惠券
		getCouponList() {
			let that = this;
			let goodsArr = [];
			let couponList = [];
			let activeList = [];
			getCoupons({
				ids: that.goodsid
			}).then(res => {
				goodsArr = res.data;
				getShopCoupons(that.mer_id).then(({ data }) => {
					couponList = goodsArr.concat(data);
					that.$set(that.coupon, 'list', couponList);
					for (let i = 0; i < couponList.length; i++) {
						if (!couponList[i].issue && activeList.length < 2) {
							activeList.push(couponList[i]);
						}
					}
					that.$set(that, 'couponList', activeList);
				});
			});
		},
		ChangCouponsUseState(index) {
			let that = this;
			that.$set(that.coupon, 'coupon', false);
		},
		//隐藏海报
		posterImageClose: function() {
			this.canvasStatus = false;
		},
		//保存海报
		Saveposters: function() {
			uni.canvasToTempFilePath({
				x: 0,
				y: 0,
				width: 280,
				height: 420,
				fileType: 'png',
				quality: 1,
				canvasId: 'myCanvas',
				success: function(res) {
					uni.saveImageToPhotosAlbum({
						filePath: res.tempFilePath,
						success() {
							uni.showToast({
								title: this.i18n.Succeed,
								duration: 2000
							});
						}
					});
				}
			});
		},
		//生产海报
		goPoster: function() {
			let that = this;
			that.$set(that, 'canvasStatus', true);
			uni.showLoading({
				title: that.i18n.Postergenerationunderway,
				mask: true
			});
			let arr2 = [that.posterbackgd, that.storeImage];
			that.isopen = false;
			let data = { type: 'wechat', action: 2 ,origin:1};
			goodsQrcode(that.goodsid, data).then(res => {
				uni.downloadFile({
					url: res.data.url, //仅为示例，并非真实的资源
					success: res => {
						arr2[2] = res.tempFilePath;
						that.$util.PosterCanvas(arr2, that.goodsitem.store_name, that.goodsitem.price, function(tempFilePath) {});
					},
					fail: function(res) {
						uni.hideLoading();
						that.$util.Tips({
							title: that.i18n.PosterQRcodegenerationfailed
						});
					}
				});
			});
		},
		downloadFilestore: function(image) {
			uni.downloadFile({
				url: image, //仅为示例，并非真实的资源
				success: res => {
					this.storeImage = res.tempFilePath;
				},
				fail: function(res) {
					uni.hideLoading();
					that.$util.Tips({
						title: that.i18n.Productiondiagramgenerationfailed
					});
				}
			});
		},
		//分享给朋友
		goFriend: function() {
			this.isopen = false;
		},
		//是否打开分享组件
		share: function() {
			this.isopen = !this.isopen;
		},
		// 收藏商品
		setCollect: function() {
			let that = this;
			if(this.isLogin){
				if (this.goodsitem.isRelation) {
					collectDel({
						type: 1,
						type_id: this.goodsid
					}).then(res => {
						that.$set(that.goodsitem, 'isRelation', !that.goodsitem.isRelation);
					});
				} else {
					collectAdd({
						type_id: this.goodsid,
						type: 1
					}).then(res => {
						that.$set(that.goodsitem, 'isRelation', !that.goodsitem.isRelation);
					});
				}
			}else{
				this.openAuto();
			}
			
		},
		goCart:function(){
			if(this.isLogin){
				uni.switchTab({
					url: `/pages/order_addcart/order_addcart?mer_id=${this.mer_id}`
				});
			}else{
				this.openAuto();
			}
		},
		//客服
		couponTap2: function() {
			if(this.isLogin){
				uni.navigateTo({
					url: `/pages/chat/customer_list/chat?mer_id=${this.mer_id}&productId=${this.goodsid}`
				});
			}else{
				this.openAuto();
			}
			
		},
		gostore() {
			if(this.isLogin){
				uni.switchTab({
					url: `/pages/index/index?mer_id=${this.mer_id}`
				});
			}else{
				this.openAuto();
			}
			
		},
		goBuy: function(e) {
			if (this.isLogin === false) {
				this.openAuto();
			} else {
				this.goCat(true);
			}
		},

		// 打开属性加入购物车
		joinCart: function(e) {
			//是否登录
			if (this.isLogin === false) {
				this.openAuto();
			} else {
				this.goCat();
			}
		},
		goCat: function(news) {
			let that = this,
				productSelect = that.productValue[this.attrValue];
			//打开属性
			if (that.attrValue) {
				//默认选中了属性，但是没有打开过属性弹窗还是自动打开让用户查看默认选中的属性
				that.attr.cartAttr = !that.isOpen ? true : false;
			} else {
				if (that.isOpen) that.attr.cartAttr = true;
				else that.attr.cartAttr = !that.attr.cartAttr;
			}
			//只有关闭属性弹窗时进行加入购物车
			if (that.attr.cartAttr === true && that.isOpen === false) return (that.isOpen = true);
			//如果有属性,没有选择,提示用户选择
			if (that.attr.productAttr.length && that.isOpen === true && productSelect.stock == 0)
				return that.$util.Tips({
					title: that.i18n.Nnderstock
				});
			if (that.attr.productSelect.cart_num == 0) {
				return that.$util.Tips({
					title: that.i18n.Umber
				});
			}
			let q = {
				mer_id: that.mer_id,
				is_new: news === undefined ? 0 : 1,
				product_id: that.goodsid,
				cart_num: that.attr.productSelect.cart_num,
				product_attr_unique: that.attr.productSelect !== undefined ? that.attr.productSelect.unique : '',
				source: this.source
			};

			//添加购物车
			postCartAdd(q)
				.then(function(res) {
					that.isOpen = false;
					that.attr.cartAttr = false;
					if (news) {
						uni.navigateTo({
							url: '/pages/users/order_confirm/index?cartId=' + res.data.cart_id
						});
					} else {
						that.$util.Tips({
							title: that.i18n.Add,
							success: () => {
								that.getCartCount(true);
							}
						});
					}
				})
				.catch(res => {
					that.isOpen = false;
					return that.$util.Tips({
						title: res
					});
				});
		},
		//获取购物车数量
		// @param boolean 是否展示购物车动画和重置属性
		getCartCount: function(isAnima) {
			let that = this;
			const isLogin = that.isLogin;
			if (isLogin) {
				getCartCounts().then(res => {
					that.CartCount = res.data[0].count;
					//加入购物车后重置属性
					if (isAnima) {
						that.animated = true;
						setTimeout(function() {
							that.animated = false;
						}, 500);
					}
				});
			}
		},

		//购物车数量加和数量减

		ChangeCartNum: function(changeValue) {
			//changeValue:是否 加|减
			//获取当前变动属性
			let productSelect = this.productValue[this.attrValue];
			//如果没有属性,赋值给商品默认库存
			if (productSelect === undefined && !this.attr.productAttr.length) productSelect = this.attr.productSelect;
			//无属性值即库存为0；不存在加减；
			if (productSelect === undefined) return;
			let stock = productSelect.stock || 0;
			let num = this.attr.productSelect;
			if (changeValue) {
				num.cart_num++;
				if (num.cart_num > stock) {
					this.$set(this.attr.productSelect, 'cart_num', stock);
					this.$set(this, 'cart_num', stock);
				}
			} else {
				num.cart_num--;
				if (num.cart_num < 1) {
					this.$set(this.attr.productSelect, 'cart_num', 1);
					this.$set(this, 'cart_num', 1);
				}
			}
		},
		// 后退
		returns() {
			uni.navigateBack({
				delta: 1
			});
		},
		// 首页
		goHome() {
			if(this.isLogin){
				uni.switchTab({
					url: `/pages/index/index?mer_id=`+globalData.mer_id
				})
			}else{
				this.openAuto();
			}
		},
		iptCartNum: function(e) {
			this.$set(this.attr.productSelect, 'cart_num', e);
		},
		attrVal(val) {
			this.$set(this.attr.productAttr[val.indexw], 'index', this.attr.productAttr[val.indexw].attr_values[val.indexn]);
		},
		selecAttr: function() {
			this.$set(this.attr, 'cartAttr', true);
			this.$set(this, 'isOpen', true);
		},
		onMyEvent: function() {
			this.$set(this.attr, 'cartAttr', false);
			this.$set(this, 'isOpen', false);
		},

		/**
		 * 获取购物车数量
		 * @param boolean 是否展示购物车动画和重置属性
		 */
		getCartCount: function(isAnima) {
			let that = this;
			getCartCounts().then(res => {
				that.CartCount = res.data[0].count;
				//加入购物车后重置属性
				if (isAnima) {
					that.animated = true;
					setTimeout(function() {
						that.animated = false;
					}, 500);
				}
			});
		},

		getdetail: function() {
			uni.showLoading({
				title: this.i18n.Loading,
				mask: true
			});
			let that = this;
			getProductDetail(this.goodsid)
				.then(res => {
					uni.hideLoading();
					that.$set(that, 'goodsitem', res.data);
					that.$set(that, 'storeImage', res.data.image);
					that.$set(that.attr, 'productAttr', res.data.attr);
					that.$set(that, 'productValue', res.data.sku);
					that.DefaultSelect();
					that.getCartCount();
					that.content = res.data.content.content;
					this.downloadFilestore(res.data.image);
					this.mer_id=res.data.merchant.mer_id
				})
				.catch(err => {
					that.$util.Tips({
						title: err
					});
					// uni.navigateBack({
					// 	delta: 1
					// });
				});
		},
		ChangeAttr: function(res) {
			let productSelect = this.productValue[res];
			if (productSelect && productSelect.stock > 0) {
				this.$set(this.attr.productSelect, 'image', productSelect.image ? productSelect.image : this.goodsitem.image);
				this.$set(this.attr.productSelect, 'price', productSelect.price);
				this.$set(this.attr.productSelect, 'stock', productSelect.stock);
				this.$set(this.attr.productSelect, 'unique', productSelect.unique);
				this.$set(this.attr.productSelect, 'cart_num', 1);
				this.$set(this, 'attrValue', res);
				this.$set(this, 'attrTxt', this.i18n.Selected);
			} else {
				this.$set(this.attr.productSelect, 'image', this.goodsitem.image);
				this.$set(this.attr.productSelect, 'price', this.goodsitem.price);
				this.$set(this.attr.productSelect, 'stock', 0);
				this.$set(this.attr.productSelect, 'unique', '');
				this.$set(this.attr.productSelect, 'cart_num', 0);
				this.$set(this, 'attrValue', '');
				this.$set(this, 'attrTxt', this.i18n.Pleaseselect);
			}
		},
		/**
		 * 默认选中属性
		 *
		 */
		DefaultSelect: function() {
			let productAttr = this.attr.productAttr;
			let value = [];
			let arr = [];
			let unSortArr = [];
			for (var key in this.productValue) {
				if (this.productValue[key].stock > 0) {
					value = this.attr.productAttr.length ? key.split(',') : [];
					break;
				}
			}
			for (let i = 0; i < productAttr.length; i++) {
				this.$set(productAttr[i], 'index', value[i]);
			}
			let productSelect = this.productValue[value.join(',')];
			if (productSelect && productAttr.length) {
				this.$set(this.attr.productSelect, 'store_name', this.goodsitem.store_name);
				this.$set(this.attr.productSelect, 'image', productSelect.image ? productSelect.image : this.goodsitem.image);
				this.$set(this.attr.productSelect, 'price', productSelect.price);
				this.$set(this.attr.productSelect, 'stock', productSelect.stock);
				this.$set(this.attr.productSelect, 'unique', productSelect.unique);

				this.$set(this, 'attrValue', value.join(','));
				this.$set(this, 'attrTxt', this.i18n.Selected);
				if (productSelect.stock == 0) {
					this.$set(this.attr.productSelect, 'cart_num', 0);
				} else {
					this.$set(this.attr.productSelect, 'cart_num', 1);
				}
			} else if (!productSelect && productAttr.length) {
				this.$set(this.attr.productSelect, 'store_name', this.goodsitem.store_name);
				this.$set(this.attr.productSelect, 'image', this.goodsitem.image);
				this.$set(this.attr.productSelect, 'price', this.goodsitem.price);
				this.$set(this.attr.productSelect, 'stock', 0);
				this.$set(this.attr.productSelect, 'unique', '');
				this.$set(this.attr.productSelect, 'cart_num', 0);
				this.$set(this, 'attrValue', '');
				this.$set(this, 'attrTxt', this.i18n.Pleaseselect);
			} else if (!productSelect && !productAttr.length) {
				this.$set(this.attr.productSelect, 'store_name', this.goodsitem.store_name);
				this.$set(this.attr.productSelect, 'image', this.goodsitem.image);
				this.$set(this.attr.productSelect, 'price', this.goodsitem.price);
				this.$set(this.attr.productSelect, 'stock', this.goodsitem.stock);
				this.$set(this.attr.productSelect, 'unique', this.goodsitem.unique || '');
				this.$set(this.attr.productSelect, 'cart_num', 1);
				this.$set(this, 'attrValue', '');
				this.$set(this, 'attrTxt', this.i18n.Pleaseselect);
			} else if (productSelect && !productAttr.length) {
				this.$set(this.attr.productSelect, 'store_name', this.goodsitem.store_name);
				this.$set(this.attr.productSelect, 'image', productSelect.image);
				this.$set(this.attr.productSelect, 'price', productSelect.price);
				this.$set(this.attr.productSelect, 'stock', productSelect.stock);
				this.$set(this.attr.productSelect, 'unique', productSelect.unique);

				this.$set(this, 'attrValue', value.join(','));
				this.$set(this, 'attrTxt', this.i18n.Selected);
				if (productSelect.stock == 0) {
					this.$set(this.attr.productSelect, 'cart_num', 0);
				} else {
					this.$set(this.attr.productSelect, 'cart_num', 1);
				}
			}
		},
		openAuto() {
			uni.showLoading({ title: this.i18n.Loggingin });
			uni.getUserProfile({
				desc: '授权',
				success: res => {
					let userInfo = res;
					userInfo.mer_id = globalData.mer_id;
					userInfo.code = this.code;
					Routine.authUserInfo(userInfo)
						.then(res => {
							this.mystore();
							uni.hideLoading();
							this.getdetail(); //获得商品
							this.getCartCount();
							this.DefaultSelect();
							this.getCouponList();
						})
						.catch(res => {
							uni.hideLoading();
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
						});
				},
				fail: res => {
					uni.hideLoading();
				}
			});
		},
		//根据appid获得商铺id
		getmerid: function() {
			let that = this;
			const id = { appid: APPID };
			getappid(id)
				.then(res => {
					getStoreDetail(res.data.mer_id)
						.then(res => {
							globalData.mer_id = res.data.mer_id;
							console.log(globalData.mer_id,'11')
						})
						.catch(res => {
							return that.$util.Tips({
								title: res
							});
						});
				})
				.catch(res => {});
		},
	},
	onShow() {
		this.getmerid();
		this.getdetail(); //获得商品
		this.getCartCount();
		this.DefaultSelect();
		this.getCouponList();
	},
	onLoad(options) {
		let that = this;
		this.goodsid = options.id; //商品id
		uni.getSystemInfo({
			success: function(res) {
				that.height = res.windowHeight;
				//res.windowHeight:获取整个窗口高度为px，*2为rpx；98为头部占据的高度；
			}
		});
		if (!this.isLogin) {
			Routine.getCode().then(code => {
				this.code = code;
			});
		}
	}
};
</script>

<style lang="scss" scoped>
// 海报
.canvas {
	width: 280px;
	height: 420px;
	position: fixed;
	left: 50%;
	transform: translateX(-50%);
	z-index: 999;
	top: 50%;
	margin-top: -357rpx;
}

.canvas .close {
	width: 46rpx;
	height: 75rpx;
	position: fixed;
	right: 0;
	top: -73rpx;
	display: block;
}

.canvas .keep {
	position: fixed;
	bottom: -20px;
	left: 50%;
	transform: translateX(-50%);
	color: #fff;
	text-align: center;
	font-size: 25rpx;
	margin-top: 10rpx;
}
.mask {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.6);
	z-index: 11;
}
// 海报
.head-wrapper {
	z-index: 999;
	display: flex;
	align-items: center;
	position: fixed;
	left: 30rpx;
	top: 0;
	/* #ifdef MP */
	height: 43px;
	/* #endif */
	/* #ifdef H5 */
	height: 114rpx;
	/* #endif */
}
.head-menu {
	display: flex;
	align-items: center;
	height: 54rpx;
	width: 140rpx;
	background: rgba(0, 0, 0, 0.25);
	border-radius: 27rpx;
	.iconfont {
		flex: 1;
		text-align: center;
		color: #fff;
		box-sizing: border-box;
		&.iconxianxingxiangzuo {
			border-right: 1px solid #fff;
		}
	}
}
.head-box {
	padding: 30rpx 0 0 0;
	background-color: #ffffff;
	.head-qian {
		display: flex;
		justify-content: space-between;
		padding: 0 30rpx;
		margin-bottom: 10rpx;
		.money {
			font-size: 28rpx;
			font-weight: bold;
			color: #fd342a;
		}
		span {
			margin-right: 30rpx;
			font-size: 48rpx;
			font-weight: bold;
			color: #fd342a;
		}
	}
	.head-title {
		padding: 0 30rpx;
		font-size: 32rpx;
		font-weight: 700;
		margin: 23rpx 30rpx 0 0;
	}
	.head-subtitle {
		display: flex;
		justify-content: space-between;
		padding: 0 30rpx;
		height: 75rpx;
		font-size: 24rpx;
		font-weight: 400;
		line-height: 75rpx;
		border-bottom: 1rpx solid #eaeaea;
		color: #82848f;
		span {
		}
	}
	.head-bottom {
		display: flex;
		justify-content: space-between;
		align-items: center;
		vertical-align: middle;
		padding: 0 30rpx;
		height: 75rpx;
		font-size: 26rpx;
		font-weight: 400;
		line-height: 37rpx;
		color: #999999;
		.activity {
			height: 18px;
			padding: 0 9px;
			border: 1px solid #f2857b;
			color: #e93323;
			font-size: 11px;
			line-height: 18px;
			position: relative;
			margin: 0 0 0 7px;
		}
		.activity:before {
			content: ' ';
			position: absolute;
			width: 3px;
			height: 4px;
			border-radius: 0 3px 3px 0;
			border: 1px solid #f2857b;
			background-color: #fff;
			bottom: 50%;
			left: -1px;
			margin-bottom: -2px;
			border-left-color: #fff;
		}
		.activity:after {
			content: ' ';
			position: absolute;
			width: 3px;
			height: 4px;
			border-radius: 3px 0 0 3px;
			border: 1px solid #f2857b;
			background-color: #fff;
			right: -1px;
			bottom: 50%;
			margin-bottom: -2px;
			border-right-color: #fff;
		}
	}
}
.store-wrapper {
	margin-top: 20rpx;
	background-color: #fff;
	.store-hd {
		padding: 30rpx;
		border-bottom: 1px solid #f5f5f5;
		.store-info {
			position: relative;
			display: flex;
			.logo {
				width: 86rpx;
				height: 86rpx;
				image {
					width: 86rpx;
					height: 86rpx;
					border-radius: 6rpx;
				}
			}
			.info {
				display: flex;
				flex-direction: column;
				justify-content: center;
				margin-left: 20rpx;
				.name {
					font-size: 28rpx;
					color: #282828;
					font-weight: bold;
				}
				.txt {
					margin-top: 8rpx;
					color: #666666;
					font-size: 22rpx;
				}
			}
			.link {
				position: absolute;
				right: 0;
				top: 50%;
				transform: translateY(-50%);
				display: flex;
				align-items: center;
				justify-content: center;
				width: 114rpx;
				height: 50rpx;
				font-size: 24rpx;
				background: linear-gradient(-90deg, #f67a38 0%, #f11b09 100%);
				border-radius: 25rpx;
				color: #fff;
			}
		}
		.score-wrapper {
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
			.item {
				color: #948d8c;
				font-size: 26rpx;
				text {
					margin-left: 10rpx;
					color: #fd342a;
				}
			}
		}
	}
}
.title {
	margin-top: 30rpx;
	font-size: 30rpx;
	color: #282828;
	height: 86rpx;
	width: 100%;
	background-color: #fff;
	text-align: center;
	line-height: 86rpx;
}
.footer {
	padding: 0 20rpx 0 30rpx;
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
	box-sizing: border-box;
	height: 100rpx;
	background-color: #fff;
	z-index: 277;
	border-top: 1rpx solid #f0f0f0;
	.item {
		font-size: 18rpx;
		color: #666;
		.iconfont {
			position: relative;
			text-align: center;
			font-size: 40rpx;
			width: 40rpx;
			height: 40rpx;

			.icongouwuche {
				font-size: 40rpx;
			}
			.num {
				color: #fff;
				position: absolute;
				font-size: 18rpx;
				padding: 2rpx 8rpx 3rpx;
				border-radius: 200rpx;
				top: -10rpx;
				right: -10rpx;
			}
		}
	}
	.bnt {
		width: 444rpx;
		height: 76rpx;
		.bnts {
			width: 222rpx;
			text-align: center;
			line-height: 76rpx;
			color: #fff;
			font-size: 28rpx;
		}
		.joinCart {
			border-radius: 50rpx 0 0 50rpx;
			background-image: linear-gradient(to right, #fea10f 0%, #fa8013 100%);
		}
		.buy {
			border-radius: 0 50rpx 50rpx 0;
			background-image: linear-gradient(to right, #fa6514 0%, #e93323 100%);
		}
		.buy[disabled] {
			background: #bbb;
		}
	}
}
.iconicon3 {
	color: #f00 !important;
}
.body-box {
	margin: 20rpx 0;
	padding: 0 30rpx;
	background-color: #ffffff;
	font-size: 28rpx;
	font-weight: 400;
	color: #999999;
	.body-box-list {
		overflow: hidden;
		padding: 20rpx 0;
		.body-box-list-title {
			font-size: 28rpx;
			font-weight: 500;
			color: #999999;
			margin-bottom: 12rpx;
		}
		.body-box-list-text {
			font-size: 28rpx;
			font-weight: 500;
			color: #222222;
		}
		.img {
			position: relative;
			margin-top: 20rpx;
			display: flex;
			view {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: center;
				margin: 0 auto;
			}
			image {
				z-index: 5;
				margin: 0 auto;
				display: block;
				display: flex;
				width: 38rpx;
				height: 38rpx;
			}

			.xian {
				position: absolute;
				left: 128rpx;
				top: 16rpx;
				height: 4rpx;
				width: 231rpx;
				background-color: #fd342a;
			}
			.xian1 {
				position: absolute;
				left: 351rpx;
				top: 16rpx;
				height: 4rpx;
				width: 231rpx;
				background-color: #bdbdbd;
			}
		}
	}
}
.content {
	display: flex;
	text-align: center;
	padding-top: 40rpx;
	.weix {
		display: flex;
		flex-direction: column;
		justify-content: center;
		flex: 1;
	}
	.haib {
		display: flex;
		flex-direction: column;
		justify-content: center;
		flex: 1;
	}
}
</style>
